<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use QrCode;
use App\User;
use Germey\Geetest\CaptchaGeetest;

use DB;
class UploadController extends Controller
{
    use CaptchaGeetest;

    public function upload()
    {

        return view('upload');
    }

    public function send(Request $request)
    {
        //判断提交方式
        if ($request->isMethod('post')) {
            // $result = $request->all();
            //文件上传
            $file = $request->file('file');
            //判断文件上传过程中是否出错
            if ($file->isValid()) {

                // 获取文件相关信息
                $originalName = $file->getClientOriginalName(); // 文件原名
                $ext = $file->getClientOriginalExtension();     // 扩展名 文件的后缀
                $realPath = $file->getRealPath();   //临时文件的绝对路径
                $type = $file->getClientMimeType();     // image/jpeg 获取文件的类别


                // 上传文件
                $filename = time() . uniqid() . '.' . $ext;

                $path = $file->move('home/upload', $filename);

                return '上传成功';
            }

            //dd($result);

        }

    }

    public function qrcode()
    {
        return QrCode::size(400)->generate('Hello,LaravelAcademy!');
        //return QrCode::format('png')->size(400)->backgroundColor(231,232,235)->merge('/public/home/upload/14766982105804a06220c30.jpg',.15)->encoding('UTF-8')->generate('http://www.baidu.com',public_path('home/upload/qrcode.png'));
    }

    public function getInfo()
    {

        //$result = DB::table('user')->get();
        $id = 13;
        $user = new User();
        $result = $user->getInfo($id);//转换为json格式
        dump($result->toJson());
        echo '<br/>';
        dd($result->toArray());

        return view('upload', ['one' => $result]);

        //dd($arr);
    }

    public function addData()
    {
        $arr[] = array(
            'name' => '杰森斯坦森.郭达', 'age' => '50', 'sex' => '1'
            //['name'=>'亚洲猫王.赵四','age'=>'40','sex'=>'0'],


        );
        $user = new User();
        $result = $user->addData($arr);
        if ($result) {
            return '添加成功';
        } else {
            return '呕 天哪,好可怕' . '哈哈康桑阿米达';
        }

    }


    public function ueUpload(Request $request)
    {
        $result = $request->all();
        dd($result);

    }

    /*
     * 模拟参数,路由的参数传值问题,
     * */
    public function test(Request $request)
    {
        //接收的参数方式?auth=值&status=值
        //判断是否是提交方式为get方式
        if($request->isMethod('get')){
            $result = $request->all();
            dump($result);
            dd($_GET);
        }


    }

}